#include    "calender.h"
#include	"setting.h"
extern lv_indev_t * indev_keypad;
static lv_calendar_date_t date;
extern lv_group_t * g;
extern int year;
extern unsigned char month;
extern unsigned char day;


/**********************end*************************/

lv_obj_t * Calender=NULL;

//highlight the date which is pressed
static void Set_Pressday_highlight(lv_event_t*e){
    lv_obj_t * Calender = lv_event_get_current_target(e);
     	if(lv_calendar_get_pressed_date(Calender, &date)) {
			lv_calendar_set_highlighted_dates(Calender,&date,1);
        }
}


void calender_to_funcion(lv_event_t*e){
	lv_obj_t*obj=lv_event_get_target(e);
	lv_group_remove_obj(obj);
	lv_indev_set_group(indev_keypad, g);
	back_to_funcion(obj);
}


//get and set today's date by wifi
static void Set_today_date(void){
	lv_calendar_set_today_date(Calender, year, month, day);
    lv_calendar_set_showed_date(Calender, year, month);
}

extern uint8_t back_flag;//0 关闭  1开启
void Calender_Init(lv_obj_t *obj){
	Calender=lv_calendar_create(obj);
	lv_obj_set_style_border_width(Calender,0,NULL);
	lv_obj_set_size(Calender,200,200);
	lv_obj_center(Calender);
	lv_calendar_header_arrow_create(Calender);
	Set_today_date();//Get and set today date
	lv_calendar_set_highlighted_dates(Calender,&date,1);//recover the highlight day
	lv_obj_add_event_cb(Calender,Set_Pressday_highlight,LV_EVENT_VALUE_CHANGED ,NULL);//highlight the date which is pressed

	if(back_flag) {lv_obj_set_style_bg_color(Calender,lv_color_hex(0x286BB4),NULL);lv_obj_set_style_bg_color(obj,lv_color_hex(0x286BB4),NULL);}
	else          {lv_obj_set_style_bg_color(Calender,lv_color_hex(0xF387B6),NULL);lv_obj_set_style_bg_color(obj,lv_color_hex(0xF387B6),NULL);}

	lv_group_add_obj(g,obj);
	lv_indev_set_group(indev_keypad, g);
	//create one btn back to the function page
	lv_obj_add_event_cb(obj,calender_to_funcion,LV_EVENT_CLICKED,NULL);
}



